class WishListsSuggestionsController < ApplicationController
  before_filter :authenticate_user!, :except => :global

  def popular
    render :json => Product.joins(:product_tag).select("products.id, text")
      .where("user_id = #{current_user.id}").order("count desc").limit(params["count"] || 20)
  end

  def suggest
    render :json => Product.joins(:product_tag).select("products.id, text")
      .where("user_id = #{current_user.id} and text like '%#{params["text"]}%'").order("count desc").limit(params["count"] || 20)
    # TODO tags + global user suggestions + global user tags
  end

  #global requests
  def global
    render :json => Product.select("id, text").where("text like '%#{params["text"]}%'").order("count").limit(20)
  end


end
